package com.tanhua.server.controller;

import com.tanhua.domain.vo.PageResult;
import com.tanhua.server.service.IMService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class IMController {

    @Autowired
    private IMService imService;

    /**
     * 添加好友
     *  POST    /contacts
     *  参数：
     *      body类型
     *          userId ： interger
     */
    @PostMapping("/contacts")
    public ResponseEntity contactUser(@RequestBody Map map) {
        Long friendId = Long.valueOf(map.get("userId").toString());
        return imService.contactUser(friendId);
    }

    /**
     * 查询联系人列表
     */
    @GetMapping("/contacts")
    public ResponseEntity<PageResult> queryContactsList(@RequestParam(defaultValue = "1") Integer page,
                                                        @RequestParam(defaultValue = "10") Integer pagesize,
                                                        @RequestParam(required = false) String keyword) {
        return this.imService.queryContactsList(page, pagesize, keyword);
    }

    /**
     * 查询被点赞列表
     * GET      /likes
     */
    @GetMapping("/likes")
    public ResponseEntity<PageResult> likes(@RequestParam(defaultValue = "1") Integer page,
                                                        @RequestParam(defaultValue = "10") Integer pagesize) {
        return this.imService.messageList(page, pagesize,1); //查询被点赞
    }

    /**
     * 查询被喜欢列表
     * GET      /loves
     */
    @GetMapping("/loves")
    public ResponseEntity<PageResult> loves(@RequestParam(defaultValue = "1") Integer page,
                                            @RequestParam(defaultValue = "10") Integer pagesize) {
        return this.imService.messageList(page, pagesize,3); //查询被点赞
    }

    /**
     * 查询被评论列表
     * GET      /comments
     */
    @GetMapping("/comments")
    public ResponseEntity<PageResult> comments(@RequestParam(defaultValue = "1") Integer page,
                                            @RequestParam(defaultValue = "10") Integer pagesize) {
        return this.imService.messageList(page, pagesize,2); //查询被点赞
    }
}
